<?php

namespace common\models\book;

use Yii;

/**
 * This is the model class for table "{{%book_stage}}".
 *
 * @property int $id
 * @property int $book_id 预约ID
 * @property int $room_id 座谈类型ID
 * @property int $room_stage_id 座谈类型ID
 * @property int $start_time 开始时间
 * @property int $end_time 结束时间
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class BookStage extends \common\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%book_stage}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['book_id', 'room_id', 'room_stage_id', 'start_time', 'end_time', 'status', 'created_at', 'updated_at'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'book_id' => '预约ID',
            'room_id' => '座谈类型ID',
            'room_stage_id' => '座谈类型ID',
            'start_time' => '开始时间',
            'end_time' => '结束时间',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function getRoomStage() {
        return $this->hasOne(RoomStage::class, ['id' => 'room_stage_id']);
    }

    /**
     * {@inheritdoc}
     */
    public function getStage() {
        return $this->hasOne(Stage::class, ['start_hour' => 'start_hour', 'end_hour' => 'end_hour'])->via('roomStage');
    }

    /**
     * {@inheritdoc}
     */
    public function getDuration() {
        return date('H:i', $this->start_time) . '-' . date('H:i', $this->end_time);
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'duration',
            'start_time',
            'end_time',
        ];
    }

}
